package com.raja.servingStation.datasources;

import org.springframework.stereotype.Component;
import org.sql2o.Connection;
import org.sql2o.Sql2o;

import java.sql.SQLException;

/**
 * 维修助手的datasource
 * Created by liuyanjun
 * on 2016/10/9 0009.
 */
@Component
public class RepairSql2oTemp {

    private Sql2o sql2o;

    public Sql2o getSql2o() {
        return sql2o;
    }

    public void setSql2o(Sql2o sql2o) {
        this.sql2o = sql2o;
    }

    /**
     * 处理事务bug
     * @param flag
     */
    public void setAutoCommit(boolean flag) {
        Connection connection = null;
        java.sql.Connection con = null;
        try{
            connection =  this.getSql2o().open();
            con = connection.getJdbcConnection();
            con.setAutoCommit(flag);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}
